
  /*global require*/
import auth from '@/store/modules/auth'
import {getNetworkType} from "./util.function";

/* 手机号码验证 */
export function isTelPhone(phoneNumber) {
  let telRule = /^1[3|4|5|6|7|8|9]\d{9}$/;
  return telRule.test(phoneNumber)
}

/* 身份证验证 */
export function isUsername(username) {
  username = username.replace(/\s*/g,"")
  let regIdNo = /^[\u4e00-\u9fa5]{2,10}$/;
  return regIdNo.test(username);
}
/* 身份证验证 */
export function isIDCard(IDCard) {
  IDCard = IDCard.replace(/\s*/g,"")
  let regIdNo = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
  return regIdNo.test(IDCard);
}

/* 获取环境UA参数 */
export function getUA() {
  let u = navigator.userAgent;
  let u2 = navigator.userAgent.toLowerCase();
  return { //移动终端浏览器版本信息
    trident: u.indexOf('Trident') > -1, //IE内核
    presto: u.indexOf('Presto') > -1, //opera内核
    webKit: u.indexOf('AppleWebKit') > -1, //苹果、谷歌内核
    gecko: u.indexOf('Gecko') > -1 && u.indexOf('KHTML') === -1, //火狐内核
    mobile: !!u.match(/AppleWebKit.*Mobile.*/), //是否为移动终端
    ios: !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/), //ios终端
    android: u.indexOf('Android') > -1 || u.indexOf('Linux') > -1, //android终端或uc浏览器
    iPhone: u.indexOf('iPhone') > -1, //是否为iPhone或者QQHD浏览器
    iPad: u.indexOf('iPad') > -1, //是否iPad
    webApp: u.indexOf('Safari') === -1, //是否web应该程序，没有头部与底部
    iosv: u.substr(u.indexOf('iPhone OS') + 9, 3),
    weixin: u2.match(/MicroMessenger/i) ? u2.match(/MicroMessenger/i).toString() === "micromessenger" : false,
    qq: u2.match(/QQ\//i) ? u2.match(/QQ\//i).toString() === "qq/" : false,
    APP: u2.match(/newLoanMarket/i) ? u2.match(/newLoanMarket/i).toString() === "newloanmarket" : false,
    ali: u.indexOf('AliApp') > -1,
    system_name: u2.indexOf('windows') > -1 ? '1' : (u2.indexOf('android') > -1 ? '3' : (u2.indexOf('macintosh') > -1 ? '4' : (u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/) ? '2' : ''))),
    system_version: '',
    equ_model: '',
    package: u2.match(/(com.[a-z.]*)(?=\/)/g) ? u2.match(/(com.[a-z.]*)(?=\/)/g).toString() : 'com.default.app',
    networkType: getNetworkType(),
  };
}

// export function getPackage() {
//   let state = auth.state;
//   let _package = getUA().package;
//   const pkg = [
//     {project_id: 100, app_id: 1, package: 'com.tutu.app'},
//     {project_id: 101, app_id: 2, package: 'com.xiong.app'},
//     {project_id: 103, app_id: 4, package: 'com.cyx.jinshuqianbao'},
//     {project_id: 104, app_id: 5, package: 'com.zy.huanqiu'},
//     {project_id: 105, app_id: 6, package: 'com.daixiaoer.app'},
//     {project_id: 105, app_id: 8, package: 'com.daixiaoer.xxkd'},
//     {project_id: 105, app_id: 13, package: 'com.cdzrtx.nezhashandianjie'},
//     {project_id: 106, app_id: 7, package: 'com.mkfq.app'},
//     {project_id: 107, app_id: 9, package: 'com.zcfq.app'},
//     {project_id: 108, app_id: 10, package: 'com.lzfq.hxy'},
//     {project_id: 108, app_id: 12, package: 'com.lzfq.lfq'},
//     {project_id: 109, app_id: 11, package: 'com.yxfq.gt'},
//   ];
//   pkg.forEach(v => {
//     if (Number(v.project_id) === Number(state.project_id) && Number(v.app_id) === Number(state.app_id)) _package = v.package;
//   });
//   return _package;
// }

/* 获取图片 */
export function getImg(config) {
  let state = auth.state;
  let version = `${new Date().getFullYear()}${new Date().getMonth()+1}`;
  try {
    let url = '';
    if (config.name === 'logo') {
      // url = '/static/images/logo/logo_' + state.project_id + '_' + state.app_id + '.png?v=' + version;
      // url = require('../assets/images/logo/logo_' + state.project_id + '_' + state.app_id + '.png');
    } else if (config.name === 'photo') {
      // url = require('/static/images/promote/temp' + config.flooring_page + '/' + config.name + config.index + '.png?v=' + version)
      url = require('../assets/images/promote/temp' + config.flooring_page + '/' + config.name + config.index + '.png');
    } else if (config.name === 'download') {
      // url = require('/static/images/promote/temp' + config.flooring_page + '/download.png?v=' + version)
      url = require('../assets/images/promote/temp' + config.flooring_page + '/download.png');
    } else if (config.name === 'btn_submit') {
      // url = '/static/images/promote/temp' + config.flooring_page + '/' + config.name + '.png'
      url = require('../assets/images/promote/temp' + config.flooring_page + '/' + config.name + '.png');
    } else {
      // url = require('../assets/images/promote/temp' + config.flooring_page + '/' + config.name + '.png?v=' + version)
      url = require('../assets/images/promote/temp' + config.flooring_page + '/' + config.name + '.png');
    }
    if (config.is64 === 1) {
      return 'background-image: url(' + url + ');'
    } else {
      return url;
    }

  } catch (e) {
    if (config.name === 'download') {
      // return require('/static/images/v1.0.0/download.png?v=' + version)
      // return require('../assets/images/v1.0.0/download.png')
    } else if (config.name === 'photo') {
      // return require('/static/images/promote/temp72/' + config.name + config.index + '.png?v=' + version)
      // return require('../assets/images/promote/temp72/' + config.name + config.index + '.png');
    } else {
      return ''
    }
  }
}